#include "core/main.h"

double ValueFunction::getValue(const vector<double> &featureVector) const
{
    double sum = 0;
    assert(featureVector.size() == _weights.size());
    for (UINT i = 0; i < _weights.size(); i++) {
        sum += featureVector[i] * _weights[i];
    }
    return sum;
}

double ValueFunction::getValue(const Frame &frame) const
{
    vector<double> featureVector;
    _transform.transform(frame, featureVector);
    return getValue(featureVector);
}

void ValueFunction::saveToFile(const string &filename) const
{
    OutputDataStream os;
    os << _transform;
    os << _weights;
    os.SaveToFile(filename);
}

void ValueFunction::loadFromFile(const string &filename)
{
    InputDataStream is;
    is.LoadFromFile(filename);
    is >> _transform;
    is >> _weights;
}